package cn.seqdata.jpa;

import java.util.AbstractMap;
import java.util.Map;
import java.util.Map.Entry;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/** id=string, name=string */
@MappedSuperclass
public class JpaString extends JpaNamed<String> {
	private static final long serialVersionUID = 1L;

	public JpaString() {
		super();
	}

	public JpaString(String id) {
		super(id);
	}

	public JpaString(String id, String name) {
		super(id, name);
	}

	public JpaString(Entry<? extends String, ? extends String> entry) {
		super(entry.getKey(), entry.getValue());
	}

	@Id
	@Column(name = "id", unique = true, nullable = false)
	@Override
	public String getId() {
		return super.id;
	}

	Map.Entry<String, String> toEntry() {
		return new AbstractMap.SimpleImmutableEntry<String, String>(getId(), getName());
	}

	@Override
	public int hashCode() {
		return ((getId() == null) ? 0 : getId().hashCode());
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		JpaString other = (JpaString) obj;
		if (getId() == null) {
			if (other.getId() != null)
				return false;
		} else if (!getId().equals(other.getId()))
			return false;
		return true;
	}
}